package com.ruoyi.base.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.tree.Tree;
import com.ruoyi.common.core.domain.entity.SysDept;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.base.domain.vo.BaseStandardSheetVo;
import com.ruoyi.base.domain.bo.BaseStandardSheetBo;
import com.ruoyi.base.service.IBaseStandardSheetService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标准投标清单
 *
 * @author zyb
 * @date 2024-09-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/base/standardSheet")
public class BaseStandardSheetController extends BaseController {

    private final IBaseStandardSheetService iBaseStandardSheetService;

    /**
     * 查询标准投标清单列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public R<List<BaseStandardSheetVo>> list(BaseStandardSheetBo bo) {
        return R.ok(iBaseStandardSheetService.queryList(bo));
    }

    /**
     * 导出标准投标清单列表
     */
    @SaCheckLogin
    @Log(title = "标准投标清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BaseStandardSheetBo bo, HttpServletResponse response) {
        List<BaseStandardSheetVo> list = iBaseStandardSheetService.queryList(bo);
        ExcelUtil.exportExcel(list, "标准投标清单", BaseStandardSheetVo.class, response);
    }

    /**
     * 获取标准投标清单详细信息
     *
     * @param sheetId 主键
     */
    @SaCheckLogin
    @GetMapping("/{sheetId}")
    public R<BaseStandardSheetVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long sheetId) {
        return R.ok(iBaseStandardSheetService.queryById(sheetId));
    }

    /**
     * 新增标准投标清单
     */
    @SaCheckLogin
    @Log(title = "标准投标清单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaseStandardSheetBo bo) {
        return toAjax(iBaseStandardSheetService.insertByBo(bo));
    }

    /**
     * 修改标准投标清单
     */
    @SaCheckLogin
    @Log(title = "标准投标清单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaseStandardSheetBo bo) {
        return toAjax(iBaseStandardSheetService.updateByBo(bo));
    }

    /**
     * 删除标准投标清单
     *
     * @param sheetIds 主键串
     */
    @SaCheckLogin
    @Log(title = "标准投标清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sheetIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] sheetIds) {
        return toAjax(iBaseStandardSheetService.deleteWithValidByIds(Arrays.asList(sheetIds), true));
    }

    /**
     * 获取标准清单树 树列表
     */
    @SaIgnore
    @GetMapping("/standardSheetTree")
    public R<List<Tree<Long>>> standardSheetTree(BaseStandardSheetBo bo) {
        return R.ok(iBaseStandardSheetService.selectstandardSheetTreeList(bo));
    }
}
